package com.bw.good.model

import com.bawei.common.model.BaseRepository
import com.bw.good.api.GoodServerApi
import com.bw.good.entity.GoodEntity
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class GoodRepository @Inject constructor(private val apiServer: GoodServerApi): BaseRepository<GoodServerApi>() {

    suspend fun loadGoodList(categoryId: Int, currentPage: Int, pageSize: Int): Flow<List<GoodEntity>> {
        return flow {
            val result = apiServer.getGoodList(categoryId, currentPage, pageSize)
            if (result.code == 200) {
                emit(result.data)
            } else {
                emit(listOf())
            }
        }
    }
}